//
//  YXVideoEditor.h
//  YXVideoKit
//
//  Created by Simon on 14-6-17.
//  Copyright (c) 2014年 Xuan Yi Xia Technology Co., LTD. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@class YXVideoComponentVideo;
@class YXVideoEditor;

typedef YXVideoComponentVideo MPTVideoComponentVideo;

@interface YXVideoEditor : NSObject
//视频尺寸
@property (nonatomic, assign) CGSize                    videoSize;
//视频码流
@property (nonatomic, assign) NSInteger                 videoRateBit;
//视频片段
@property (nonatomic, readonly, retain) NSMutableArray  *clips;
//原音关闭
@property (nonatomic, assign) BOOL                      muteOriginalSound;
//原音大小
@property (nonatomic, assign) CGFloat                  originalSoundVolume;
//时间跳转数组，这个数组有值就不会用clips
@property (nonatomic, retain) NSMutableArray            *timeJumpArray;
//混音数组
@property (nonatomic, retain) NSMutableArray            *audioMixArray;
//视频合成后时长
@property (nonatomic, readonly, assign) CMTime          duration;
//以下三个仅作记录用
//播放方向
@property (nonatomic, readonly, assign) BOOL reversePlay;
//声音效果
@property (nonatomic, readonly, assign) NSInteger soundEffectIndex;
//视频速度
@property (nonatomic, readonly, assign) CGFloat playRate;
//尾声渐消
@property (nonatomic, assign) BOOL donotFadeOut;
@property (nonatomic, retain) NSMutableArray             *specailClipArray;


@property (nonatomic, assign) CGFloat nominalFrameRate;

@property (nonatomic, readonly, retain) AVMutableComposition       *composition;
@property (nonatomic, readonly, retain) AVMutableVideoComposition  *videoComposition;
@property (nonatomic, readonly, retain) AVMutableAudioMix          *audioMix;
@property (nonatomic, readonly, retain) NSMutableArray             *commentaryTrackMixArray;
@property (nonatomic, retain) NSString *xunfeiID;
@property (nonatomic, retain) NSString *xunfeiText;
@property (nonatomic, retain) NSString *xunfeiSoundPath;

@property (nonatomic, strong, readonly) AVMutableComposition *orginalComposition;
@property (nonatomic, strong, readonly) AVMutableComposition *bgmComposition;

//使用原视频尺寸
- (void)useOriginalVideoSize;

//将视频片段组织成视频
- (void)buildCompositionForClips;
- (void)buildSimpleCompositionForClips;
- (void)buildSmartCompositionForClips;
- (void)buildMultipleFrameCompositionForConfig:(NSArray*)videoInfoArray;

- (void)buildVideoComposition:(AVMutableVideoComposition *)videoComposition forComposition:(AVMutableComposition *)composition;

//导出
- (void)exportWithAnimatedLayer:(CALayer*)layer outputPath:(NSString*)outputPath processingBlock:(void(^)(CGFloat))processingBlock completeHanlder:(void(^)(NSString*))handler;
- (void)exportWithQuality:(NSString *)presetName andAnimatedLayer:(CALayer*)layer outputPath:(NSString*)outputPath processingBlock:(void(^)(CGFloat))processingBlock completeHanlder:(void(^)(NSString*))handler;
- (void)exportWithBitRate:(NSNumber*)bitRate andAnimatedLayer:(CALayer*)layer outputPath:(NSString*)outputPath processingBlock:(void(^)(CGFloat))processingBlock completeHanlder:(void(^)(NSString*))handler;

//组织clip中的视频片段，对timeJumpArray进行维护，达到片段跳跃、无声等效果
- (void)arrangeClipWithIndex:(NSInteger)index timeRange:(CMTimeRange)timeRange muteAudio:(BOOL)muteAudio;

//获取播放所需
- (void)getPlayerItem:(AVPlayerItem**)playerItemOut andSynchronizedLayer:(AVSynchronizedLayer**)synchronizedLayerOut withAnimatedLayer:(CALayer*)animatedLayer;
//最普通的拼接视频
- (AVPlayerItem*)buildNormalPlayerItem;
//同步动画图层
- (AVSynchronizedLayer*)buildSynchronizedLayer:(AVPlayerItem*)playerItem animatedLayer:(CALayer*)animatedLayer;

//获取视频片段的总时长
- (CMTime)getTotalDurationForClips;
//对整个视频进行裁剪
- (void)setTimeRangeForClips:(CMTimeRange)timeRange;
//获取整个视频的裁剪数据
- (CMTimeRange)getTimeRangeForClips;

//添加声音
- (void)arrangeAudioTrackFromFile:(NSString*)url;
- (void)arrangeAudioTrackFromFile:(NSString*)url repeatable:(BOOL)repeatable;
- (void)arrangeAudioTrackFromFile:(NSString*)url repeatable:(BOOL)repeatable trackRange:(CMTimeRange)trackRange;
- (void)arrangeAudioTrackFromFile:(NSString*)url repeatable:(BOOL)repeatable trackRange:(CMTimeRange)trackRange trackVolume:(CGFloat)volume;
- (void)arrangeAudioTrackFromFile:(NSString*)url timeRange:(CMTimeRange)timeRange;
- (void)arrangeAudioTrackFromFile:(NSString*)url timeRange:(CMTimeRange)timeRange trackRange:(CMTimeRange)trackRange;

- (void)setEditorReversePlay:(BOOL)reversePlay;
- (void)setEditorSoundEffect:(NSInteger)soundEffectIndex;
- (void)setEditorPlayRate:(CGFloat)playRate;

- (void)appendSpecailClip:(NSString*)url timeRange:(CMTimeRange)timeRange;
- (void)replaceTimeJumpConfigAt:(NSInteger)index withFile:(NSString*)path;
- (void)clearArrangedClips;
- (void)clearArrangedSoundClips;

- (void)duplicateClipAt:(NSInteger)index;
- (void)removeClipAt:(NSInteger)index;
- (void)exchangeClipAtIndex:(NSInteger)index1 withIndex:(NSInteger)index2;
- (void)replaceAt:(NSInteger)index withComponent:(YXVideoComponentVideo*)component;
- (void)appendVideoComponents:(NSArray*)array;

- (void)arrangeAnimatedLayer:(CALayer *)animatedLayer;
+ (AVAsset *)suitAudioAsset:(NSString *)audioPath timeRangeOfAudioAsset:(CMTimeRange)timeRange duration:(CMTime)duration;

//音量
- (void)arrangeAudioTrackFromFile:(NSString *)url repeatable:(BOOL)repeatable volume:(CGFloat)volume;
- (void)setVideoClipsVolume:(CGFloat)volume;


@end
